# 导入时间和画布
import turtle
import datetime

# 获取目前的时间,设置画布，设置笔的大小和起始位置
def main():
    turtle.setup(800, 350, 200, 200)
    turtle.penup()
    turtle.forward(-300)
    turtle.pensize(5)
    turtle.hideturtle()
    today = datetime.datetime.now().strftime("%Yn%my%dr")
    drawDate(today)
    turtle.done()

# 将时间时间一个一个输出
def drawDate(time):
    turtle.pencolor("red")
    for t in time:
        if t == 'n':
            turtle.write("年", font=("Arial", 18, "normal"))
            turtle.pencolor("green")
            turtle.forward(40)
        elif t == 'y':
            turtle.write("月", font=("Arial", 18, "normal"))
            turtle.pencolor("blue")
            turtle.forward(40)
        elif t == 'r':
            turtle.write("日", font=("Arial", 18, "normal"))
        else:
            drawWalk(eval(t))

    # 判断该值是否需要走这一步
def drawWalk(d):
     # 判断数字应该走那一步
    drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 6, 8] else drawLine(False)
    turtle.left(90)
    drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
    turtle.left(180)
    turtle.penup()
    turtle.forward(20)

# 判断是否放下笔
def drawLine(val):
    drawGap()
    turtle.pendown() if val else turtle.penup()
    turtle.forward(40)
    drawGap()
    turtle.right(90)

# 设置间隔
def drawGap():
    turtle.penup()
    turtle.forward(5)

main()